(function ($, root) {
    var zongTime = 0;
    var frameId = null;
    var listPre = 0;
    var t = 0;
    //渲染总时间
    function renderAllTime(time) {
        zongTime = time;
        var time = formatTime(time)
        $('.all-time').html(time);
    }

    //处理总时间
    function formatTime(t) {
        t = Math.round(t)
        var m = Math.floor(t / 60);
        var s = t - m * 60;
        if (m < 10) {
            m = '0' + m;
        }
        if (s < 10) {
            s = '0' + s;
        }

        return m + ":" + s;
    }

    //state
    function start() {
        time = new Date().getTime();
        Math.floor(time);

        function frame() {
            var frameTime = new Date().getTime();
            console.log(time, frameTime)
            // 实时的更新时间  - 总时间  / 总时间 * 1000
            var pre = listPre + (frameTime - time) / (zongTime * 1000);
            update(pre)
            // setInterval(function(){
            //     frame()
            // },1000)
            //每次触发 刷新页面
            frameId = requestAnimationFrame(frame);
        }
        frame()
    }

    function stop() {
        cancelAnimationFrame(frameId);
        var frameTime = new Date().getTime();
        // 实时的更新时间  - 总时间  / 总时间 * 1000
        var pre = (frameTime - time) / (zongTime * 1000);
        listPre += pre;

    }
    //←时间
    function update(pre) {
        var time = pre * zongTime;
        var time1 = Math.floor(time)
        $('.cur-time').html('0' + ':' + time1);
        $('.pro-top').css({
            transform: "translateX(-"+ time1+"%)"
        })
    }
    
    root.pro = {
        renderAllTime: renderAllTime,
        start: start,
        stop: stop
    }

})(window.Zepto, window.player || (window.player = {}))